#!/bin/bash

# === 1. 格式化 Hadoop NameNode 并启动 Hadoop ===
cd /usr/local/hadoop-3.1.4 || exit

echo "清除 HDFS 临时目录..."
rm -rf tmp

echo "格式化 HDFS..."
hdfs namenode -format

echo "启动 Hadoop 所有服务..."
start-all.sh

echo "查看启动的 Java 进程..."
jps

# === 2. 启动 MySQL 与 Hive Metastore 服务 ===
echo "启动 MySQL 数据库..."
systemctl start mysqld.service

echo "启动 Hive Metastore..."
 hive --service metastore &

# === 3. 启动 Spark SQL CLI ===
echo "进入 Spark SQL CLI..."
cd /usr/local/spark-3.2.1-bin-hadoop2.7/bin/ || exit
./spark-sql

# === 4.在 CLI 中执行 SQL 查询 ===
# （spark_init.sql）

# === 5. 启动 Spark 服务 ===
echo "启动 Spark 服务..."
spark-submit --class com.tipdm.WordCount /opt/wer.jar
hdfs dfs -put /opt/house.csv /